package org.zachary.prosocialbehaviorservice.domain.aggregate_model.activity;

import jakarta.persistence.*;
import lombok.*;
import org.springframework.data.domain.AbstractAggregateRoot;
import org.zachary.prosocialbehaviorservice.domain.aggregate_model.activity.event.*;

import java.io.Serial;
import java.io.Serializable;
import java.time.Instant;

@EqualsAndHashCode(callSuper = true)
@Entity
@AllArgsConstructor
@Table(name="activity_item")
@Data
public class ActivityItem extends AbstractAggregateRoot<ActivityItem>  implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;
    @Id
    private Integer id;

    private String title;
    private String content;
    private Instant startDate;
    private Instant endDate;
    private Instant publishDate;
    private String qrCode;
    private Integer number;

    private ActivityItem(Integer id, String title, String content,
                        Instant startDate, Instant endDate,
                        String qrCode,Integer number) {
        this.id = id;
        this.title = title;
        this.content = content;
        this.startDate = startDate;
        this.endDate = endDate;
        this.qrCode = qrCode;
        this.number = number;
    }



    public static ActivityItem buildForAdd(Integer id,String title,String content,
                                           Instant startDate, Instant endDate,String qrCode,Integer number) {
        return new ActivityItem(id, title, content, startDate, endDate, qrCode,number);
    }


    protected ActivityItem() {}
    public void addActivityItem(){
        registerEvent(new AddActivityItemEvent(this));
    }
    public void fileAddActivityItem(){
        registerEvent(new FileActivityItemEvent(this));
    }
    public void removeActivityItem(){
        registerEvent(new RemoveActivityItemEvent(this));
    }
    public void modifyActivityItem(){
        registerEvent(new ModifyActivityItemEvent(this));
    }
    public void decrementByOne() {
        registerEvent(new UserJoinActivityItem(this));
    }
}
